// https://leetcode.cn/problems/guess-number-higher-or-lower/
// Created by ade on 2022/8/4.
//
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<numeric>

using namespace std;

class Solution {
public:
    int guessNumber(int n) {
        int left = 0;
        while (left < n) {
            int mid = left + (n - left) / 2;
            int res = guess(mid);
            if (res == 0) return mid;
            if (res > 0)
                left = mid + 1;
            else
                n = mid;
        }
        return left;

    }
};